package com.yang.controller.wx;

import com.yang.bean.MarketUser;
import com.yang.bean.common.BaseParam;
import com.yang.bean.common.BaseRespVo;
import com.yang.bean.common.CommonData;
import com.yang.bean.zdd.vo.GoodsCategoryVo;
import com.yang.bean.zdd.vo.GoodsDetailVo;
import com.yang.bean.zdd.vo.ListInWxVo;
import com.yang.service.admin.GoodsService;
import com.yang.utils.UserUtil;
import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author: 杨庆
 * @since: 2022.9.9 15:54
 * @description:
 */

@RestController
@RequestMapping("wx/goods")
public class WXGoodsController {
    @Autowired
    GoodsService goodsService;
    @Autowired
    DefaultWebSessionManager defaultWebSessionManager;

    @RequestMapping("count")
    public BaseRespVo count() {
        Long goodsNum = goodsService.count();
        return BaseRespVo.ok(goodsNum);
    }

    @RequestMapping("category")
    public BaseRespVo category(Integer id) {
        GoodsCategoryVo data = goodsService.category(id);
        return BaseRespVo.ok(data);
    }

    @RequestMapping("list")
    public BaseRespVo list(BaseParam baseParam, Integer categoryId, Integer brandId, String keyword, HttpServletRequest request) {
        Integer userId = UserUtil.getUserId(request, defaultWebSessionManager);
        ListInWxVo data = goodsService.listInWx(baseParam, categoryId, brandId, keyword, userId);
        return BaseRespVo.ok(data);
    }

    @RequestMapping("detail")
    public BaseRespVo detail(Integer id, HttpServletRequest request) {
        Integer userId = UserUtil.getUserId(request, defaultWebSessionManager);
        GoodsDetailVo data = goodsService.detailInWx(id, userId);
        return BaseRespVo.ok(data);
    }

    @RequestMapping("related")
    public BaseRespVo related(Integer id) {
        CommonData data = goodsService.related(id);
        return BaseRespVo.ok(data);
    }
}
